﻿
////////////////////////////////////////////////////////////////////////////////////////////
// 文件名: ETL_TargetSystemBLL.gen.cs
//
// 模块名称: ETLTargetBll
//
// 作者: LPC
//
// 历史记录（记录修改记录，修改文件后请添加修改记录，注明修改时间、修改人，修改内容）:
// 13-2-1    LPC    创建文件
////////////////////////////////////////////////////////////////////////////////////////////

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using Common;
using DAL;
using Model;

namespace BLL
{
    /// <summary>
    /// ETL_TargetSystem表业务逻辑层
    /// </summary>
    public class EtlTargetSystemBLL : BaseBLL
    {
        public EtlTargetSystemBLL(LoginInfo info)
        {
            loginInfo = info;
        }
        const string ErrorCodeSelect = "";    //查询异常编码
        const string ErrorCodeInsert = "";    //添加异常编码
        const string ErrorCodeUpdate = "";    //修改异常编码
        const string ErrorCodeDelete = "";    //删除异常编码

        /// <summary>
        /// 根据GUID字段获取ETL_TargetSystemInfo实体对象
        /// </summary>
        /// <param name="guid"></param>
        /// <returns></returns>
        public EtlTargetSystemInfo GetInfoById(string guid)
        {
            try
            {
                return new EtlTargetSystemDAL(loginInfo).GetInfoById(guid);
            }
            catch (Exception ex)
            {
                Logger.LogError("ETL_TargetSystemBLL", "GetInfo", AppError.EROR, 0, ex, "获取ETLTargetBll信息出错。",
                                String.Format("guid = {0}", guid));
                throw new SystemException(ErrorCodeSelect, ex);
            }
        }

        /// <summary>
        /// 往ETL_TargetSystem表内添加新记录
        /// </summary>
        /// <returns>添加记录索引值</returns>
        public int Insert(EtlTargetSystemInfo eTLTargetSystemInfo)
        {
            try
            {
                int identity = new EtlTargetSystemDAL(loginInfo).Insert(eTLTargetSystemInfo);
                return identity;
            }
            catch (Exception ex)
            {
                Logger.LogError("ETL_TargetSystemBLL", "Insert", AppError.EROR, 0, ex, "添加ETLTargetBll信息出错。", null);
                throw new SystemException(ErrorCodeInsert, ex);
            }
        }

        /// <summary>
        /// 更新ETL_TargetSystem表记录
        /// </summary>
        /// <param name="eTLTargetSystemInfo"> </param>
        public int Update(EtlTargetSystemInfo model)
        {
            try
            {
                return new EtlTargetSystemDAL(loginInfo).Update(model);
            }
            catch (Exception ex)
            {
                Logger.LogError("ETL_TargetSystemBLL", "Update", AppError.EROR, 0, ex, "更新ETLTargetBll信息出错。",
                                String.Format("GUID = {0}", model.GUID));
                throw new SystemException(ErrorCodeUpdate, ex);
            }
        }
        public void DeleteContact(string guid, int tp)
        {
            try
            {
                new EtlTargetSystemDAL(loginInfo).DeleteContact(guid, tp);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void UpdateContact(IDataParameter[] par)
        {
            try
            {
                new EtlTargetSystemDAL(loginInfo).UpdateContact(par);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 根据GUID字段获取ETL_TargetSystemInfo实体对象
        /// </summary>
        /// <param name="par"> </param>
        public string Delete(string guid, string targetSysCode)
        {
            return new EtlTargetSystemDAL(loginInfo).Delete(guid, targetSysCode);
        }

        /// <summary>
        /// 根据GUID字段获取ETL_TargetSystemInfo实体对象
        /// </summary>
        /// <param name="par"> </param>
        public void UpdateStatus(IDataParameter[] par)
        {
            try
            {
                new EtlTargetSystemDAL(loginInfo).UpdateState(par);
            }
            catch (Exception ex)
            {
                Logger.LogError("ETL_TargetSystemBLL", "Delete", AppError.EROR, 0, ex, "删除ETLTargetBll信息出错。",
                                "");
                throw new SystemException(ErrorCodeDelete, ex);
            }
        }

        /// <summary>
        /// 根据GUID字段获取ETL_TargetSystemInfo实体对象
        /// </summary>
        /// <param name="par"> </param>
        /// <returns>List<ETL_TargetSystemInfo/>实体对象</returns>
        public IList<EtlTargetSystemInfo> GetList(IDataParameter[] par)
        {
            try
            {
                return new EtlTargetSystemDAL(loginInfo).GetList(par);
            }
            catch (Exception ex)
            {
                Logger.LogError("ETL_TargetSystemBLL", "GetInfo", AppError.EROR, 0, ex, "获取ETLTargetBll信息出错。",
                                "");
                throw new SystemException(ErrorCodeSelect, ex);
            }
        }

        /// <summary>
        /// 根据GUID字段获取ETL_TargetSystemInfo实体对象
        /// </summary>
        /// <param name="code"> </param>
        /// <returns>List<ETL_TargetSystemInfo/>实体对象</returns>
        public EtlTargetSystemInfo GetList(string code)
        {
            try
            {
                return new EtlTargetSystemDAL(loginInfo).GetList(code);
            }
            catch (Exception ex)
            {
                Logger.LogError("ETL_TargetSystemBLL", "GetInfo", AppError.EROR, 0, ex, "获取ETLTargetBll信息出错。",
                                "");
                throw new SystemException(ErrorCodeSelect, ex);
            }
        }
        /// <summary>
        /// 根据所有的
        /// </summary>
        /// <param name="par"> </param>
        /// <returns>List<ETL_TargetSystemInfo/>实体对象</returns>
        public IList<EtlTargetSystemInfo> GetAllList()
        {
            try
            {
                return new EtlTargetSystemDAL(loginInfo).GetAllList();
            }
            catch (Exception ex)
            {
                Logger.LogError("ETL_TargetSystemBLL", "GetInfo", AppError.EROR, 0, ex, "获取ETLTargetBll信息出错。",
                                "");
                throw new SystemException(ErrorCodeSelect, ex);
            }
        }

        /// <summary>
        /// 根据GUID字段获取ETL_TargetSystemInfo实体对象
        /// </summary>
        /// <param name="par"> </param>
        /// <returns>List<ETL_TargetSystemInfo/>实体对象</returns>
        public int GetListCount(IDataParameter[] par)
        {
            try
            {
                return new EtlTargetSystemDAL(loginInfo).GetListCount(par);
            }
            catch (Exception ex)
            {
                Logger.LogError("ETL_TargetSystemBLL", "GetInfo", AppError.EROR, 0, ex, "获取ETLTargetBll信息出错。",
                                "");
                throw new SystemException(ErrorCodeSelect, ex);
            }
        }

        public string GetPwdFromDataBase()
        {
            return new EtlTargetSystemDAL(loginInfo).GetPwdFromDataBase();
        }

        public int InsertAddlogin(EtlTargetSystemInfo model, string pwd)
        {
            try
            {
                int identity = new EtlTargetSystemDAL(loginInfo).InsertAddlogin(model, pwd);
                return identity;
            }
            catch (Exception ex)
            {
                Logger.LogError("ETL_TargetSystemBLL", "Insert", AppError.EROR, 0, ex, "添加ETLTargetBll信息出错。", null);
                throw new SystemException(ErrorCodeInsert, ex);
            }
        }

        public int InsertAdduser(EtlTargetSystemInfo model)
        {
            try
            {
                int identity = new EtlTargetSystemDAL(loginInfo).InsertAdduser(model);
                return identity;
            }
            catch (Exception ex)
            {
                Logger.LogError("ETL_TargetSystemBLL", "Insert", AppError.EROR, 0, ex, "添加ETLTargetBll信息出错。", null);
                throw new SystemException(ErrorCodeInsert, ex);
            }
        }

        public int InsertAddbasegrant(EtlTargetSystemInfo model)
        {
            try
            {
                int identity = new EtlTargetSystemDAL(loginInfo).InsertAddbasegrant(model);
                return identity;
            }
            catch (Exception ex)
            {
                Logger.LogError("ETL_TargetSystemBLL", "Insert", AppError.EROR, 0, ex, "添加ETLTargetBll信息出错。", null);
                throw new SystemException(ErrorCodeInsert, ex);
            }
        }

        public DataTable TargetSystemGetViewList()
        {
            return new EtlTargetSystemDAL(loginInfo).TargetSystemGetViewList();

        }

        public DataTable SelectViewColumnConfig(IDataParameter[] paras1)
        {
            return new EtlTargetSystemDAL(loginInfo).SelectViewColumnConfig(paras1);
        }

        public int InsertViewColumnConfig(IDataParameter[] paras)
        {
            return new EtlTargetSystemDAL(loginInfo).InsertViewColumnConfig(paras);
        }

        public int DeleteViewColumnConfig(IDataParameter[] paras1)
        {
            return new EtlTargetSystemDAL(loginInfo).DeleteViewColumnConfig(paras1);
        }

        public DataTable SelectViewColumnConfigWhereCondition(IDataParameter[] paras1)
        {
            return new EtlTargetSystemDAL(loginInfo).SelectViewColumnConfigWhereCondition(paras1);
        }

        public int InsertViewColumnConfigWhereCondition(IDataParameter[] paras)
        {
            return new EtlTargetSystemDAL(loginInfo).InsertViewColumnConfigWhereCondition(paras);
        }

        public int DeleteViewColumnConfigWhereCondition(IDataParameter[] paras1)
        {
            return new EtlTargetSystemDAL(loginInfo).DeleteViewColumnConfigWhereCondition(paras1);
        }
         
        public int InsertTargetViewConfig(IDataParameter[] paras)
        {
            return new EtlTargetSystemDAL(loginInfo).InsertTargetViewConfig(paras);
        }

        public int DeleteTargetViewConfig(IDataParameter[] paras1)
        {
            return new EtlTargetSystemDAL(loginInfo).DeleteTargetViewConfig(paras1);
        }

        public int InsertAddextgrant(IDataParameter[] parasgrant)
        {
            return new EtlTargetSystemDAL(loginInfo).InsertAddextgrant(parasgrant);
        }

        public int ExeScriptPro(IDataParameter[] parasgrant)
        {
            return new EtlTargetSystemDAL(loginInfo).ExeScriptPro(parasgrant);
        }


        public DataTable GetDBInfo(SqlParameter[] paramsdb)
        {
            return new EtlTargetSystemDAL(loginInfo).GetDBInfo(paramsdb);
        }

        public DataTable GetNumTargetViewByST(SqlParameter[] targetview)
        {
            return new EtlTargetSystemDAL(loginInfo).GetNumTargetViewByST(targetview);
        }


        public int SetStepConfig(IDataParameter[] parasStep)
        {
            return new EtlTargetSystemDAL(loginInfo).SetStepConfig(parasStep);
        }

        public int GetTargetCountByCode(SqlParameter[] par)
        {
            return new EtlTargetSystemDAL(loginInfo).GetTargetCountByCode(par);
        }

        public int UpdateExternalStatus(string username, int status, string guid)
        {
            return new EtlTargetSystemDAL(loginInfo).UpdateExternalStatus(username, status, guid);
        }

        #region ETL_TargetSystem

        public List<EtlTargetSystemInfo> GetList(string targetSysName, string expIDs
           , string orderBy, bool asc
          , int pageIndex, int pageSize, out int recordCount)
        {
            EtlTargetSystemDAL dal = new EtlTargetSystemDAL(loginInfo);
            var list = dal.GetList(targetSysName, expIDs
                 , orderBy, asc
            , pageIndex, pageSize, out  recordCount);
            return list;
        }

        public EtlTargetSystemInfo GetSystemInfoById(string guid)
        {
            EtlTargetSystemDAL dal = new EtlTargetSystemDAL(loginInfo);
            return dal.GetSystemInfoById(guid);
        }

        public int InsertWithExist(EtlTargetSystemInfo sourceInfo)
        {
            try
            {
                int result = 0;
                EtlTargetSystemDAL dal = new EtlTargetSystemDAL(loginInfo);
                if (dal.GetLoginname(sourceInfo.TargetSysCode) > 0)
                {
                    result = 3;
                }
                var list = dal.GetByNameAndCode(sourceInfo.TargetSysName, string.Empty);
                if (list.Count == 0)
                {
                    result = dal.Insert(sourceInfo);
                }
                else
                {
                    result = 2;
                }
                return result;
            }
            catch (Exception ex)
            {
                Logger.LogError("ETL_TargetSystemBLL", "InsertWithExist", AppError.EROR, 0, ex, "添加TargetSystemBLL信息出错。", null);
                throw new SystemException(ErrorCodeInsert, ex);
            }
        }

        /// <summary>
        /// 更新ETL_TargetSystem表记录
        /// 插入成功：1
        /// TargetSysName相同：2
        /// </summary>
        /// <param name="sourceInfo"></param>
        /// <returns></returns>
        public int Update2(EtlTargetSystemInfo sourceInfo)
        {
            try
            {
                int result = 0;
                EtlTargetSystemDAL dal = new EtlTargetSystemDAL(loginInfo);
                var list = dal.GetByNameWithOutGUID(sourceInfo.GUID, sourceInfo.TargetSysName);
                if (list.Count == 0)
                {
                    result = dal.Update2(sourceInfo);
                }
                else
                {
                    result = 2;
                }
                return result;
            }
            catch (Exception ex)
            {
                Logger.LogError("ETL_TargetSystemBLL", "Update", AppError.EROR, 0, ex, "更新ETLSourceBll信息出错。",
                                "");
                throw new SystemException(ErrorCodeUpdate, ex);
            }
        }

        #endregion

    }
}